<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Platformset extends Stourweb_Controller
{

    public function before()
    {
        parent::before();
    }


    function action_index(){
        $id = $_REQUEST['id'];
        $platform='';
        if(count(explode(',',$id))==1){
            $typeid = $_REQUEST['typeid'];
            $table = St_Functions::table_field($typeid)[3];
            $platform = DB::select('platform')->from($table)->where('id','=',$id)->execute()->get('platform');
        }
        $client=St_Functions::platform_conf();
        if(in_array($typeid,[23])){
            unset($client[5]);
        }
        $this->assign('client',$client);
        $this->assign('id',$id);
        $this->assign('platform',explode(',',$platform));
        $this->display("stourtravel/platformset/index");

    }

    function action_ajax_set(){
        $id = $_REQUEST['id'];
        $typeid = $_REQUEST['typeid'];
        $platform= Arr::get($_POST, 'platform');
        $table = St_Functions::table_field($typeid)[3];
        foreach (explode(',',$id) as $index => $item) {
            if($item){
                DB::update($table)->set(array('platform' =>$platform?:''))
                    ->where('id', '=', $item)
                    ->execute();
            }
        }
        echo "ok";
    }

}